package cuit.cx.groupcomment.dao.impl;


import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.sun.org.apache.bcel.internal.generic.NEW;

import cuit.cx.groupcomment.dao.OrdersDAO;
import cuit.cx.groupcomment.model.Orders;

public class OrdersDAOImpl extends SqlMapClientDaoSupport implements OrdersDAO
{
	
	private Logger log = Logger.getLogger(Orders.class);


    public OrdersDAOImpl() {
        super();
    }

    public int addOrder(Orders record)
    {
    	int result = -1;
    	try
		{
			result = (Integer) getSqlMapClientTemplate().insert("addOrder", record);
		}
		catch (DataAccessException e)
		{
			//e.printStackTrace();
			log.error("add Order failed!", e);
		}
    	
       return  result;
    }


    public int updateOrder(Orders record) 
	{
		int rows = -1;
		try
		{
			rows = getSqlMapClientTemplate().update("updateOrder", record);
		}
		catch (DataAccessException e)
		{
			//e.printStackTrace();
			log.error("update Order failed!", e);
		}
		return rows;
	}
  
    public Orders findOrderById(Integer id) 
    {
        Orders record = null;
        	
        try
		{
			record = (Orders) getSqlMapClientTemplate().queryForObject("getOrdersById", id);
		}
		catch (DataAccessException e)
		{
		//	e.printStackTrace();
			log.error("find order error!",e);
		}
        return record;
    }



    public int deleteOrder(Integer id) 
	{
		int rows = -1;

		try
		{
			rows = getSqlMapClientTemplate().delete("deleteOrder", id);
		}
		catch (DataAccessException e)
		{
			//e.printStackTrace();
			log.error("delete order failed!", e);
		}
		return rows;
	}

	@SuppressWarnings("unchecked")
	public List<Orders> findOrderByGroupId(Integer groupId)
	{
		List<Orders> orders = null;
		try
		{
			orders = getSqlMapClientTemplate().queryForList("getOrderByGroupId", groupId);
		}
		catch (DataAccessException e)
		{
			e.printStackTrace();
		}
		return orders;
	}

   
}